from django.db import models

# Create your models here.
class Category(models.Model):
    cname = models.CharField(max_length=128,unique=True,verbose_name='类别名称')

    class Meta:
        db_table='t_category'
        verbose_name_plural='类别'

    def __repr__(self):
        return "%s"%self.cname


class Tags(models.Model):
    tname = models.CharField(max_length=32,unique=True,verbose_name='标签名称')

    class Meta:
        db_table = 't_tags'
        verbose_name_plural='标签'

    def __repr__(self):
        return "%s"%self.tname


class Post(models.Model):

    #标题
    title = models.CharField(max_length=128,unique=True)
    #摘要信息
    desc = models.TextField()
    #主要内容
    content = models.TextField()
    #创建时间
    created = models.DateField(auto_now=True)
    #修改时间
    modified = models.DateTimeField(auto_now=True)
    #类别
    category = models.ForeignKey(Category,on_delete=Category)
    #有几个标签
    tags = models.ManyToManyField(Tags)

    class Meta:
        db_table = 't_post'
        verbose_name_plural='帖子'

    def __repr__(self):
        return "%s"%self.title